package com.yikaiye.android.yikaiye.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.databinding.DialogChooseBinding;

/**
 * 相册、拍照
 */
public abstract class ChoosePhotoDialog {
    private final Dialog dialog;

    public ChoosePhotoDialog(Activity activity) {
        DialogChooseBinding binding = DialogChooseBinding.inflate(LayoutInflater.from(activity));
        dialog = new Dialog(activity, R.style.prompt_progress_dialog_dimenabled);
        dialog.setContentView(binding.getRoot(), new LinearLayout.LayoutParams
                (LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        dialog.setCancelable(true);
        Window dialogWindow = dialog.getWindow();
        if (dialogWindow != null) {
            // 去除遮罩效果
//        dialogWindow.setDimAmount(0f);
            WindowManager.LayoutParams lp = dialogWindow.getAttributes();
            dialogWindow.setGravity(Gravity.BOTTOM);
            dialogWindow.setWindowAnimations(R.style.main_menu_animStyle);
            // lp.x = 266; // 新位置X坐标
            // lp.y = Utils.dip2px(activity, 300); // 新位置Y坐标
            lp.width = WindowManager.LayoutParams.MATCH_PARENT;
            dialogWindow.setAttributes(lp);
        }
        binding.tvCancel.setOnClickListener(v -> dismissDialog());
        binding.tvChooseOne.setOnClickListener(view1 -> {
            chooseOne();
            dismissDialog();
        });

        binding.tvChooseTwo.setOnClickListener(view2 -> {
            chooseTwo();
            dismissDialog();
        });
    }

    public abstract void chooseOne();

    public abstract void chooseTwo();

    public void showDialog() {
        dialog.show();
    }

    public void dismissDialog() {
        if (dialog != null) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }
        }
    }
}
